Robotics 1.0
Lesson: 3 :Lights, Action, CPX!

Purpose: Students will learn to program the CPX to use buttons, the slide switch, and the buzzer output.

No. of. Classes

1 - 1 (Time : 1 hour and 30 minutes, each group has maximum 4 students).

Materials Required
  • CPX Board

  • USB cable - micro USB

Prior knowledge

  • Understanding Python indentation and code blocks
  • Basic familiarity with the CPX board such as identifying Buttons A & B and the built-in NeoPixel LEDs
  • Exercises

    Exercise:1



    Learn how to write loops in CircuitPython and change NeoPixel colors using Buttons A and B.

    Click here to view the instructions and code



    Exercise:2



    Change NeoPixel colors using the slide switch.

    Click here to view the instructions and code

    Exercise:3



    Play a sound using the CPX buzzer.

    Click here to view the instructions and code

    Exercise:4



    High and Low (Pseudocode)

    Click here to view the instructions and code

    Solution



    Here is the Solution:

  • Click here to see the solution video for Exercise 1
  • Click here to see the solution video for Exercise 2
  • Click here to see the solution video for Exercise 3
  • Click here to see the solution Document for Exercise 4
  • Teacher's Instruction
    1. Ensure that Mu Editor is installed on all student computers and set to CircuitPython mode.
    2. If the file code.py is not visible in the CIRCUITPY drive, reflash the UF2 file.
    3. Copy the required library folder (adafruit_circuitplayground) into the lib folder on the CPX.
    4. Allow students to test the program using Buttons A & B. Ask them to try changing colors and adding delays using time.sleep()
    5. Explain common Python errors such as IndentationError.
    6. Click here for more details about the CPX.
    7. Why must the CPX code be inside a while True: loop?
    8. Where do you think the program is stored inside the CPX? Think about what you learned in Digital Literacy about memory.